package widgets;

import java.awt.Color;
import java.awt.Graphics;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;

public class DoubleRectangleWidget extends Widget
{
    private static final long serialVersionUID = 1L;
	private PropertyChangeSupport propertyChangeSupport;
    private int innerWidth;
    private int innerHeight;
    private int outerWidth;
    private int outerHeight;
    private Color innerBackground;
    private Color outerBackground;
    
    public CircleWidget()
    {
        propertyChangeSupport = new PropertyChangeSupport(this);
        innerBackground = Color.GREEN ;
        outerBackground = Color.RED ;
        innerWidth = 20;
        innerHeight = 20;
        outerWidth = 50;
        outerHeight = 50;
        setSize(outerWidth, outerHeight);
    }

    public void addPropertyChangeListener(PropertyChangeListener l)
    {
        propertyChangeSupport.addPropertyChangeListener(l);
    }

    public void removePropertyChangeListener(PropertyChangeListener l)
    {
        propertyChangeSupport.removePropertyChangeListener(l);
    }
    
    public void paint(Graphics g)
    {
        super.paint(g);
        g.setColor(innerBackground);
        setBackground(outerBackground);
        g.fillOval(0, 0, wbRadius.intValue() - 1, wbRadius.intValue() - 1);
        setSize(outerWidth, outerHeight);
    }
    
    public int getinnerWidth() 
    {
		return innerWidth;
	}
    
    public int getinnerHeight() 
    {
		return innerHeight;
	}
    
    public int getouterWidth() 
    {
		return outerWidth;
	}
    
    public int getouterHeight() 
    {
		return outerHeight;
	}
    
    public Color getinnerBackground() {
		return innerBackground;
	}
    
    public Color getouterBackground() {
		return outerBackground;
	}
    
    public void destroy()
	{	
	}    
    
    public void parseCommand(String cmd)
	{
		String[] tokens = cmd.split("( )+", 6) ;
		if ( tokens.length != 6 ) return ;
		Color outColor = null ;
        Color inColor = null ;
		int iw, ih ,ow, oh;
		try {
			inColor = Color.decode(tokens[0]);
            outColor = Color.decode(tokens[1]);
			iw = Integer.parseInt(tokens[2]) ;
			ih = Integer.parseInt(tokens[3]) ;
            ow = Integer.parseInt(tokens[4]) ;
			oh = Integer.parseInt(tokens[5]) ;
		} catch ( Exception e ) {
			return ;
		}
		
		outerBackground = outColor ;
        innerBackground = inColor;
		innerWidth = iw;
		innerHeight = ih;
        outerWidth = ow;
        outerHeight = oh;
		
		setSize(outerWidth,outerHeight) ;
		this.setBackground(outerBackground) ;
	}
    
	public String toCommand()
	{
		return String.format("%s %s %d %d %d %d", 
				getHexColor(innerBackground), getHexColor(outerBackground), innerWidth, innerHeight, outerWidth, outerHeight) ;
	}
    
    
    public void setinnerBackground(Color innerBackground) 
    {
		this.innerBackground = innerBackground;
	}
    
    public void setouterBackground(Color outerBackground) 
    {
		this.outerBackground = outerBackground;
	}
    
    public void setinnerWidth(int innerWidth) 
    {
		this.innerWidth = innerWidth;
	}
    
    public void setinnerHeight(int innerHeight) 
    {
		this.innerHeight = innerHeight;
	}
    
    public void setouterWidth(int outerWidth) 
    {
		this.outerWidth = outerWidth;
	}
    
    public void setouterHeight(int outerHeight) 
    {
		this.outerHeight = outerHeight;
	}
    
    private String getHexColor(Color cColor)
	{
        return String.format("#%02x%02x%02x", 
        		cColor.getRed(), cColor.getGreen(), cColor.getBlue() ) ;
	}
}